/* @INLINE FILE standalone.login.bloc.js =============================================================
	* Login functions
	* 
	* VAR
	* 
	* FUNC
	* this.toggle_login
	*/
    
    this.toggle_login = function(n){
    	if(!mod_backdoor&&!(is_popup&&config.require_login&&n==0)){
			if(tg==0){
				if($('fc_loginbox').style.display == _b){
					jQ(".fc_ob").html(fc_chat.toggle_btn(1,1));
				}else{
					jQ(".fc_ob").html(fc_chat.toggle_btn(1,0));
				}
				//closePopup();
			}
	    	fc_chat.toggle_login_box(n);
    	}
        return false;
    };
    var _change_name=0;
    
    this.sign_in = function(elem,n){
    	if(!l){
    		if(tg=='1'){
    			login_lock=true;
        		fc_chat.prepare_disabled_mode();
    		}else{
		    	_change_name=1;
		    	if(n){
		    		current_pos=n;
		    	}
				if(elem){
					current_pos=(jQ(elem).parent().parent().attr("id")=='fc_t1a'?1:0);
				}
    		}
    		fc_chat.toggle_login(current_pos);
    	}
    	return false;
    };
    var loginbox_lock = false;
    var lock_login = function(n){
    	$('fc_lenter').disabled = n;
        toggle_alt_login((n?0:1));
        lock_login_exit(n);
        loginbox_lock=n;
    };
    var lock_login_exit = function(n){
    	$('fc_lexit').disabled=n;
		$('fc_lexit2').disabled=n;
	};
    var toggle_alt_login = function(enabled){
    	if(config.facebook_connect&&fb_child){
    		fb_post('toggle'+enabled);
    	}
    };
    this.toggle_login_exit = function(){
    	if(jQ('#fc_lexit').attr('disabled')!='disabled'){
    		fc_chat.toggle_login(0);
    	}
    };
    var unlock_login_box = function(v){
    	var elem = v;
    	if(!v){
    		elem = $('fc_loginbox');
    	}
    	if(elem.style.display == _b){
        	login_lock=false;
        	if(tg==1){
        		clrOverlay();
    		}
        }
    	if(!v){
    		elem.style.display=_n;
    	}
    };
    this.toggle_login_box = function(n) {
        v = $('fc_loginbox');
        unlock_login_box(v);
        v.style.display = (v.style.display == _b ? _n: _b);
        if(v.style.display == _b){
        	if(!loginbox_initialized){
        		document.body.appendChild(v);
        	}
        	$('fc_logintxt1')[_i] = "<img style='vertical-align:text-bottom;' src='"+_h+"signin.png' border=0>&nbsp;&nbsp;" +__(60);
        	$('fc_logintxt')[_i] = '';
        	fc_chat.close_boxes(null,1);
        	if(tg==1||is_popup||mod_backdoor){
        		if(is_popup||mod_backdoor){
        			var top=(jQ(window).height() - jQ(v).height() ) / 2+jQ(window).scrollTop();
        			var left = ( jQ(window).width() - jQ(v).width() ) / 2+jQ(window).scrollLeft() +300 + "px";
        			if(top<90)top=90;
                	jQ(v).css({"top": top + "px","left": ( jQ(window).width() - jQ(v).width() ) / 2+jQ(window).scrollLeft() + "px"});
                	if(is_popup){
                		window['set_popup_header'](Math.max(50,top-70),config.full_page_login);
                		login_lock=true;
                	}
                	if(mod_backdoor){
                		_t.uid='-1';
                		window['set_login_header']();
                	}
        		}else{
	        		var coords = fc_chat.returnElementCoordinates((_t.m==0&&ww?ww.frame[0]:chat_panel));
	        		v.style.position = (ww&&ww.fixed?'fixed':'absolute');
	        		v.style.top=(coords.y+Math.floor((EN(chat_panel.style.height)+45)/2)-Math.floor(jQ(v).height()/2))+'px';
	                v.style.left=(coords.x+Math.floor((EN(chat_panel.style.width)+10)/2)-div(login_box_width,2))+'px';
                }
            }else{
        		position_elements(n);
        	}
        	v.style.zIndex=z_b+1010;
        	var panel_css = (tg==0?_widget.login_panel:main_panel.login_panel);
        	jQ('#fc_loginbox').css({
        			"box-shadow":panel_css.box_shadow,
        			"-webkit-box-shadow":panel_css.box_shadow,
        			"background-color":panel_css.background_color,
        			"border":panel_css.border
        	});
        	if(config.facebook_connect&&!loginbox_initialized){
        		jQ("#fc_fb_login").html("<div id='fc_fb_load' style='position:relative;left:60px;height:15px;font-size:10pt'>"+__(356,'Loading...')+"</div><iframe id='fc_fb_frame' onload='fc_chat.fb_loaded()' src='"+fb_src+"'" +
        		"scrolling='no' frameborder='0' style='border:none; visibility:hidden;overflow:hidden; width:365px; height:45px;' allowTransparency='true'></iframe>");
        	}
        	jQ('div.fc_lb_text').css(panel_css.font.smalltext_css);
        	jQ('span.fc_lb_textfield').css(panel_css.font.textfield_description_css);
        	jQ('input.fc_lb_field').attr("style",panel_css.textfield_css);
        	jQ('#fc_lenter').val((_change_name?__(340,"Set"):__(58)));
        	lock_login(false);
        	loginbox_initialized=true;
        }else{
			if(tg==1&&_t.uid=='-1'||connection_state==1){
				if(config.require_login){
					lgin=0;
					set_widget_start(1);
					//if(!integrated){
						//jQ("div.fc_controlbox .fc_ob1").html(fc_chat.toggle_btn(0,1,0));
			        	//jQ("div.fc_toolbar .fc_ob1").html(fc_chat.toggle_btn(0,1,1));
					//}
				}else{
					jQ("div.fc_t1").html(__(104));
				}
				request_login=false;
				connection_state=0;
				fc_chat.closeChat();
			}
        }
    };
    this.logout = function() {
    	if(!l){
	    	fc_chat.prepare_disabled_mode();
	    	if(tg=='1'){
	    		show_alertbox(__(97)); //show alert box
	    		 tCL('0');
	    	}else{
	    		fc_chat.close_boxes();
	    	}
	    	jQ("div.fc_t1").html(__(97));
	        if(getC(config.user_cookie)!='-1'){
            	passConnLost=true;
            }
            setC(config.user_cookie, '-1');
            die(0);
	        setTimeout("fc_chat.logout2()",2000);
    	}
        return false;
    };
    this.logout2 = function(){
        	if(request_login){
            	passConnLost=true;
            }
            setC(config.user_cookie, '-1');
            close_alert_box();
            l = false;
        	if(_t.m==1&&!request_login){
        		req = '00001[';
        		fc_chat.toggleHide();
        	}else{
	        	if (!is_popup&&tg == '1'&&!guest) {
	        		clrOverlay();
	                this.open_chat_box();
	            }
	            _t.uid='-1';
	            if(!config.require_login){
	            	//jQ(".fc_ob1").html(fc_chat.toggle_btn(0,0));
	            	jQ(".fc_ob").html(fc_chat.toggle_btn(1,0));
	            }else{
	            	//jQ("div.fc_controlbox .fc_ob1").html(fc_chat.toggle_btn(0,1,0));
		        	//jQ("div.fc_toolbar .fc_ob1").html(fc_chat.toggle_btn(0,1,1));
	            	jQ(".fc_ob").html(fc_chat.toggle_btn(1,1));
	            }
	            if(request_login){
		            die(0);
	            }
	            var outTxt=startText_wrap(config.startText);
	            if(!config.require_login){
	            	outTxt=__(101);
	            }
	            if(guest){
	            	outTxt=__(159)+loading_icon_small;
	            }
	            jQ("div.fc_t1").html(outTxt);
	            if(is_popup&&config.require_login){
	            	prep_for_signin();
	            }
        	}
        	l = true;
    };
    var prep_for_signin = function(){
    	connection_state=1;
    	close_alert_box();
    	reset_panels();
    	fc_chat.toggle_login(1);
    	jQ("div.fc_t1").html(__(393,'Please sign in.'));
    };
    this.login = function(typ) {
        logged_in = false;
        var valid=true;
        if(_t.uid=='-1'&&config.require_login){
        	valid=fc_chat.setLogin(typ);
        	screen_name=new_screen_name;
        	auth_token=new_auth_token;
        }
        if (valid) {
        	if(!config.require_login&&_t.uid=='-1'&&!request_login){
        		screen_name='g:' + __(1);
        		auth_token='';
        		for(var i=0;i<15;i++){
        			auth_token+=Math.floor(Math.random()*9);
        			auth_token = jGo.MD5.hex_md5(auth_token);
        		}
        	}else{
        		prep_for_new_connection();
        		lgin = 0;
        	}
        	locked = 1;
        	_t.inSession = 1;
        	this.loadFromLogin();
        }
        passConnLost=false;
        loginTimeout=null;
        request_login=false;
    };
    this.sendLogin = function(){
    	fc_chat.login2();
    };
    this.login2 = function(typ){
    	setC(pauseCookie,'0');
    	if(config.require_login){
    		fc_chat.login(typ);
    		return false;
    	}
    	l=true;
    	if(fc_chat.setLogin(typ)){
    		if(request_login){
    			l=false;
    			screen_name=new_screen_name;
            	auth_token=new_auth_token;
    			fc_chat.login(typ);
    			guest=false;
    		}else{
    			fc_chat.closeVid();
    			if(typ){
    				fc_chat.loginAfterServerValidation();
    			}else{
    				fc_chat.requestServerValidation();
    			}
    		}
    	}else{
    		l=false;
    	}
    };
    var prep_for_new_connection = function(){
	    lD = 1;
		pass = 1;
		lgin = 1;
		if(ff3&&tg == 1){
			chatroom_panel_inner.style.display=_n;
			private_chat_panel_inner.style.display=_n;
			chat_archive_panel.style.display=_n;
			private_archive_panel.style.display=_n;
			info_panel.style.display=_n;
		}
		fc_chat.opfxLoader();
		if(top_chat_panel_inner){
			top_chat_panel_inner[_i]='<div style="background-color:transparent;width:'+default_chat_room_width+'px">'+wrap_chat_window_alert(__(120),1)+'</div>';
		}
	};
    this.requestServerValidation = function(){
    	var len=checkLength(new_screen_name);
    	var initLen = 3 + len + new_auth_token.length;
        req = zpad_left(initLen)+ 'f' + zpad_left(len,2) + new_screen_name + new_auth_token;
        sendReq(1);
    };
    this.loginAfterServerValidation = function(){
        request_login=true;
		fc_chat.logout2();
		screen_name=new_screen_name;
		auth_token=new_auth_token;
		guest=false;
    };
    var new_screen_name;
    var new_auth_token;
    this.setLogin = function(typ){
    	if(!typ){
	    	v = $('fc_luname');
	        new_screen_name = v.value;
	        v.value = '';
	        v = $('fc_lpass');
	        new_auth_token = v.value;
	        v.value = '';
    	}
        //jQ(".fc_ob1").html(fc_chat.toggle_btn(0,0));
        jQ(".fc_ob").html(fc_chat.toggle_btn(1,0));
        $('fc_logintxt')[_i] = "<b>"+__(158)+"</b>" + loading_icon;
        lock_login(true);
        new_screen_name=jGo.util.trim(new_screen_name);
        if(!typ){
	        if(validate(new_screen_name, new_auth_token)){
	        	new_auth_token = jGo.MD5.hex_md5(new_auth_token);
	        	return true;
	        }else{
	        	return false;
	        }
        }else{
        	return true;
        }
    };
    function validate(ln, lp) {
        if (ln.length > 2 && ln.length < 21 && lp.length > 2 && lp.length < 21) {
            if ( ! reg.test(ln) &&! reg2.test(lp)) {
            	if(ln.length>=__(1).length && ln.toLowerCase().substr(0,__(1).length)==__(1)){
            		setTimeout("fc_chat.errString(2)", 500);
            		return false;
            	}else{
            		return true;
            	}
            }
        }
        setTimeout("fc_chat.errString(1)", 500);
        return false;
    };
    this.errString = function(ss) {
    	v=$('fc_logintxt');
    	if(ss==1){
    		v[_i] = __(61);
    	}else if (ss==2){
    		v[_i] = __(62);
    	}else if (ss==3){
        		v[_i] = __(63);
    	}else if (ss==4){
    		v[_i] = __(64);
    	}
    	//if(tg==0){
    		//jQ("div.fc_controlbox .fc_ob1").html(fc_chat.toggle_btn(0,1,0));
        	//jQ("div.fc_toolbar .fc_ob1").html(fc_chat.toggle_btn(0,1,1));
    	//}
    	lock_login(false);
        return true;
    };
    var exit = function(disabled){
    	
    };
    this.loadFromLogin = function() {
        if (top == self) {
            var x = null;
            try {
                x = $('fc_sChat');
            }
            catch(err) {}
            if (getC(tglCookie) != "0" && (is_popup||getC(pauseCookie) != "1") && x != null) {
            	rstCon();
                getConObj();
                if (document.getElementById && document.getElementsByTagName && document.createElement) {
                    l = true;
                    ev = '1';
                    a = new userRecord();
                    getPageData();
                    if (_t.inSession == 1) {
                        if (dmn == _n) {
                            d1 = "1"
                        }
                        for (var i = 0; i < 22; i ++ ) {
                            curr_state[i] = '0';
                        }
                        if (hU == '1') {
                            getPageUsers();
                            curr_state[6] = '1';
                        } else {
                            pL = '000:';
                        }
                        initOptions();
                        var _dtm = get_cdata(0);
                        if (_dtm == _n) {
                            ts = 'display:'+_n;
                            dtm = 0;
                        }
                        _t.uid='-1';
                        if (d1 != '0') {
                            if ((auth_token != null) && (auth_token != "") && (auth_token != "0")) {
                            	var slen = checkLength(screen_name);
                            	var account_id_len = account_id.length;
                            	session_token='';
                            	for(var i=0;i<8;i++){
	                                session_token+= String.fromCharCode((parseInt(Math.random()*1000)%93)+34);
                            	}
                            	session_token = session_token.replace(/>/g, '!');
                                var initLen = 7 + slen + account_id_len + auth_token.length + session_token.length + bump_package.length+auth_package.length;
                                var status = (bump_package==''?0:1);
                                status += (auth_package==''?0:2);
                                str = '.:' + config.chat_id + zpad_left(initLen) +  'V' + zpad_left(slen,3) + zpad_left(account_id_len,2);
                                str+='' + auth_token + '' + session_token + '' + screen_name  + '' +account_id + '' + status + '' + bump_package + '' + auth_package + String.fromCharCode(10);
                                account_id='';
                                auth_package='';
                                bump_package='';
                                var strLen = 9 + pL.length;
                                var len;
                                //if (strLen < 10) {
                                    //len = '0000' + strLen;
                               // } else if (strLen < 100) {
                                    len = '000' + strLen;
                                //} else if (strLen < 1000) {
                                    //len = '00' + strLen;
                                //} else if (strLen < 10000) {
                                    //len = '0' + strLen;
                                //} else {
                                    //len = strLen;
                                //}
                                str += len + '2' + d1 + pageKey + pL  + avatar_package;
                                avatar_package='';
                                connectionString = str; 
                                set_room=true;
                                opener_room=current_room;
                                this.t = setTimeout("fc_chat.begConPre()", 1000);
                                widget_loading();
                                if((tg=='1'||is_popup)&&jQ('#fc_loginbox').css('display')==_n){show_alertbox(__(100)+loading_icon)};
                            } else {
                            	set_widget_start(-1);
                            }
                        }
                    }
                }
            } else {
                if (x != null && _t.inSession == 1) {
                	if (getC(pauseCookie) != "1"){
                		jQ(".fc_ob").html(fc_chat.toggle_btn(2,1));
                	}
                	//jQ(".fc_ob1").html(fc_chat.toggle_btn(0,0));
                }
            }
        } else {
            getPageData();
            //if (hU == '1' && window.parent.fc_chat.getMode() == 1) {
            //    clearTimeout(window.parent.fc_chat.t);
            //    window.parent.fc_chat.t = setTimeout("window.parent.fc_chat.sendNewPageReq()", 1500);
            //}
        };
    };
    
    var stripWWW = function(_url){
    	var p1 = "http://www.";
    	var p2 = "https://www.";
    	var url = window.location.href;
    	if(url.indexOf(p1)==-1&&url.indexOf(p2)==-1){
    		if(_url.indexOf(p2)==0){
    			_url=_url.replace(p2,"https://");
    		}
    		if(_url.indexOf(p1)==0){
    			_url=_url.replace(p1,"http://");
    		}
    	}
    	return _url;
    };   
    function getLoginDetails(){
    	l=true;
    	var cur_url = window.location.href.split("?");
    	jQ.post(stripWWW(forum_proxy) + (cur_url.length>1?'?' + cur_url[1]:''), {f:0},
    		fc_chat.auth,"html"
    	);
    	return false;
    };
    this.auth = function(data){
    	l=false;
    	auth_login(data,0);
    };
    var auth_login = function(postResponse,fb){
		var loginPackage = '';
	    //console.log(postResponse);
		    var response=postResponse.split("<fcchatresponse>");
		    if(response.length>1){
		    	loginPackage = response[1];
		    }
			if(loginPackage==''){  // offline
			if(fb){
				//console.log('not connected');
				$('fc_logintxt')[_i] = "<b>"+__(355,'Authorization Failed')+"...</b><br>";
				lock_login(false);
				return false;
			}
				if(get_cdata(14)=='3'){
					createBumpPackage();
    				_t.uid='-1';
    				_t.inSession=0;
    				if(config.require_login){
	    				setC(config.user_cookie, '-1');
	                	if(_t.m==0&&tg==0){
	                		set_widget_start(1);
	                	}
	                	if(tg==1){
	                		chatroom_panel_inner[_i]='';
	                		prep_for_signin();
	                		return false;
	                	}
    				}
				}
				if(get_cdata(14)=='2'&&_t.uid=='-1'&&tg==0){
					put_cdata(0,14);
    				_t.inSession=0;
    				if(config.require_login){
	    				setC(config.user_cookie, '-1');
	                	if(_t.m==0&tg==0){
	                		set_widget_start(1);
	                	}
    				}
				}
				if(_t.uid=='-1'&&config.require_login){
					set_widget_start(1);
				}else{
					fc_chat.loader_cont();
				}
            	return false;
            }
			var data = loginPackage.split('&');
			account_id = data[0];
			auth_token = data[1];
			loginPackage=loginPackage.substr(account_id.length+auth_token.length+2);
			var name_length = parseInt(loginPackage.substr(0,3),10);
			var _screen_name=loginPackage.substr(3,name_length);
			session_token = getC(config.session_cookie);
			var diff_user=0;
	    	if (session_token&&(session_token.split('>')).length>2){
	    		var tokens=session_token.split('>');
	    		if(tokens[1].toLowerCase()!=_screen_name.toLowerCase()||tokens[2].toLowerCase()!=account_id.toLowerCase()){
	    			diff_user=1;
	    		}
	    	}
			if(!fb){
			    automatic_login=1;
			}
			//get Avatar
	        avatar_package='';
	        integrated_avatar='';
	        if(config.import_default_avatar){
    	        var response2=postResponse.split("<fcchatresponse2>");
    		    if(response2.length>1){
    		    	avatar_package = response2[1];
    		    }
    		    integrated_avatar=avatar_package;
    		    if(avatar_package!=''&&avatar_check(avatar_package,diff_user)){
    				put_cdata('',18);
    				var avalen = avatar_package.length+1;
    				avatar_package=String.fromCharCode(10)+zpad_left(avalen)+'T'+avatar_package;
    			}else{
    				avatar_package='';
    			}
	        }
			if(get_cdata(14)!='3'||_t.uid=='-1'||diff_user){
    			screen_name=_screen_name;
    			auth_package=loginPackage.substr(3+name_length);

    	        createBumpPackage();
    	        logged_in = false;
    	        locked = 1;
    	        _t.inSession = 1;
    	        
				if(fb){
			        fb_login();
				}else{
					widget_loading(1);
		    	    fc_chat.loadFromLogin();
				}
			}else{
				fc_chat.loader_cont();
            	return false;
			}
		};
    /*
     * createBumpPackage
     * When a new login is create, the previous user must be bumped to
     * make room for the new user. This function sets up the userID
     * and session info that will be used to sign them off
     */
    var createBumpPackage = function(){
    	session_token = getC(config.session_cookie);
    	if (session_token){
    		session_token = session_token.split('>')[0];
    	}
        if ((session_token == null) || (session_token == "0")) {
            session_token = ""
        }
        if (session_token != ""&&_t.uid!='-1') {
	    _t.uid = _t.uid + '';
            var str =  _t.uid.length + '' + zpad_right(_t.uid) + session_token;
            bump_package=str;
        }
    };
    
    //standalone.lobin.bloc.js =============================================================@END FILE*/